package _nio._channel;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author: huangya
 * @Date: 2021/06/23
 * @Description:
 */
public class FileChannelWriteDemo {

    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("E:\\test.txt");
        FileChannel fileChannel = fos.getChannel();

        String str = "hello1";
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(str.getBytes());
        byteBuffer.flip();
        fileChannel.write(byteBuffer);
        fos.close();
    }
}
